{% extends 'lib/_base.html' %}
{% load static %}
{% block title %}智慧星光众包平台URL查询{% endblock title %}

{% block header_tail %}
<link rel="stylesheet" href="{% static 'public/CodeMirror/lib/codemirror.css' %}">
<link rel="stylesheet" href="{% static 'public/ComboSelect/css/combo.select.css' %}">
<link rel="stylesheet" href="{% static 'public/CodeMirror/theme/lesser-dark.css' %}">
<link rel="stylesheet" href="{% static 'public/CodeMirror/addon/dialog/dialog.css' %}">
<link rel="stylesheet" href="{% static 'public/CodeMirror/addon/search/matchesonscrollbar.css' %}">
<link rel="stylesheet" href="{% static 'public/ComboSelect/css/combo.select.css' %}">
<link rel="stylesheet" href="{% static 'zhongbao/config/css/main.css' %}">
<!-- Select2 -->
<link rel="stylesheet" href="{% static 'plugins/select2/select2.min.css' %}">

<style>
    #zhongbao_create_html {
        width: 390px;
        border: 1px red solid;
        background: #3df151;
        height: 1300px;
    }

    #zhongbao_create_html p b {
        display: inline-block;
        width: 20%;
        text-align: right;
    }

    #zhongbao_create_html .zhongbao_content_xml {
        overflow: auto;
        background: #EEEEEE;
        height: 170px;
    }
</style>
{% endblock header_tail %}

{% block body_middle %}
<div>
    <p id="zhongbao_button_pass_reject" style="background-color: #736e6e;margin: 0;">
        <!--        <button id="zhongbao_pass_button" class="btn btn-primary" onclick="zhongbao_pass_api()">-->
        <!--            合格-->
        <!--        </button>-->
        <button id="zhongbao_reject_button" class="btn btn-primary" data-toggle="modal" data-target="#rejectMessage">
            不合格
        </button>
    </p>
</div>


<div class="nav-tabs-custom">
    <ul class="nav nav-tabs">
        {% for tabledata in config_info_list %}
        {% if forloop.counter == 1 %}
        <li class="active"><a href="#tab_{{ forloop.counter }}" data-toggle="tab">{{ tabledata.0.value }}</a></li>
        {% endif %}
        <li><a href="#tab_{{ forloop.counter }}" data-toggle="tab">{{ tabledata.0.value }}</a></li>
        {% endfor %}
    </ul>
    <div class="tab-content">
        {% for tabledata in config_info_list %}
        {% if forloop.counter == 1 %}
        <div class="tab-pane active" id="tab_{{ forloop.counter }}">
            <div id="zhongbao_create_html">
                {% for tab in tabledata %}
                {% if tab.tag == 1 %}
                <p>
                    <b>{{ tab.key }}</b>
                    <span><div class="zhongbao_content_xml">{{ tab.value }}</div></span>
                </p>
                {% elif tab.tag == 2 %}
                <p>
                    <b>{{ tab.key }}</b>
                    <span><div class="zhongbao_content_xml">{{ tab.value | safe }}</div></span>
                </p>
                {% elif tab.tag == 3 %}
                <p>
                    <b>{{ tab.key }}</b>
                <div class="zhongbao_content_xml">
                    {% for img_url in tab.value %}
                    <img src="{{ img_url }}" title="{{ img_url }}" width="110px" height="110px">
                    {% endfor %}
                </div>
                </p>
                {% elif tab.tag == 4 %}
                <p>
                    <b>{{ tab.key }}</b>
                <div class="zhongbao_content_xml">
                    {% for video_url in tab.value %}
                    <p>{{ video_url }}</p><br><br>
                    {% endfor %}
                </div>
                </p>
                {% else %}
                <div class="input-group">
                    <span class="input-group-addon" style="width: 140px">{{ tab.key }}</span>
                    <input type="text" class="config-input select2" value="{{ tab.value }}" style="width: 200px">
                </div>
                <br>
                {% endif %}
                {% endfor %}
            </div>
        </div>
        {% else %}
        <div class="tab-pane" id="tab_{{ forloop.counter }}">
            <div id="zhongbao_create_html">
                {% for tab in tabledata %}
                {% if tab.tag == 1 or tab.tag == 4 %}
                <p>
                    <b>{{ tab.key }}</b>
                    <span><div class="zhongbao_content_xml">{{ tab.value }}</div></span>
                </p>
                {% elif tab.tag == 2 %}
                <p>
                    <b>{{ tab.key }}</b>
                    <span><div class="zhongbao_content_xml">{{ tab.value | safe }}</div></span>
                </p>
                {% elif tab.tag == 3 %}
                <p>
                    <b>{{ tab.key }}</b>
                <div class="zhongbao_content_xml">
                    {% for img_url in tab.value %}
                    <img src="{{ img_url }}" title="{{ img_url }}" width="110px" height="110px">
                    {% endfor %}
                </div>
                </p>
                {% else %}
                <div class="input-group">
                    <span class="input-group-addon">{{ tab.key }}</span>
                    <input type="text" class="config-input select2" value="{{ tab.value }}">
                </div>
                <br>
                {% endif %}
                {% endfor %}
            </div>
        </div>
        {% endif %}
        {% endfor %}
    </div>
    <!-- /.tab-content -->
</div>

<!--不合格模态框-->
<div class="modal fade" id="rejectMessage" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" style="top:10%">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title">
                    <span type="button" class="btn btn-default" onclick="reject(0)"
                            data-dismiss="modal">确认(新增质检)
                    </span>
                    <span type="button" class="btn btn-default"
                            data-dismiss="modal">取消
                    </span>
                    <span type="button" class="btn btn-default" onclick="reject(1)"
                            data-dismiss="modal">确认(维护质检)
                    </span>
                </h4>
            </div>
            <div id="rejectMsgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                <div style="padding: 10px;">
                    <form class="bs-example bs-example-form" role="form">
                        <div class="input-group">
                            <span class="input-group-addon">任务ID</span>
                            <input type="text" id="config_id" class="form-control" value="{{ cid }}"
                                   disabled>
                        </div>
                        <br>
                        {% for error_type in error_type_list %}
                        <div class="input-group">
                                <span class="input-group-addon">
                                    <input type="checkbox" name="cvalue" value="{{error_type}}">
                                </span>
                            <input type="text" class="form-control" value="{{error_type}}" disabled>
                        </div>
                        <br>
                        {% endfor %}
                        <div class="input-group">
                            <span class="input-group-addon">其他</span>
                            <input class="form-control" id="other_cvalue">
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="{% static 'plugins\jQuery\jquery-2.2.3.min.js' %}"></script>
<script type="text/javascript">
    // 防止重复点击
    var isClick = true;
    $("button").on("click", function () {
        if (isClick) {
            isClick = false;
            //事件
            console.log($(this).attr("data-val"));
            //定时器
            setTimeout(function () {
                isClick = true;
            }, 3000);//一秒内不能重复点击
        }
    });
    console.log('{{ data }}')
</script>

<!--不合格-->
<script type="text/javascript">
    var input_config_id = $("#config_id").val();
    if (!input_config_id) {
        $("#config_id").removeAttr("disabled");
        $("#config_id").attr("placeholder", "没有查询到配置ID，请手动输入...");
    }

    function reject(type) {
        // 获取选中复选框的值
        var ids = "";
        $('input[name="cvalue"]:checked').each(function () {
            ids += $(this).val() + ',';
        });//得到选中复选框的value

        var remark = $('#other_cvalue').val();

        //去掉最后一个“，”号
        var cvalue = ids.substring(0, ids.lastIndexOf(","));

        var config_id = $("#config_id").val();

        $.ajax(
            {
                url: "{% url 'configQC:save_err' %}",
                type: "POST",
                dataType: "json",
                data: {
                    'csrfmiddlewaretoken': '{{ csrf_token }}',
                    'config_id': config_id,
                    'cvalue': cvalue,
                    'remark': remark,
                    'test_url': '{{ url }}',
                    'webname': '{{ webname }}',
                    'author': '{{ author }}',
                    'savename': '{{ savename }}',
                    'ctime': '{{ data.ctime }}',
                    'gtime': '{{ data.gtime }}',
                    'savetime': '{{ savetime }}',
                    'channel_url': '{{ channel_url }}',
                    'channel_name': '{{ channel_name }}',
                    'dtype': type
                },
                success: function (result) {
                    alert(result.message);
                    window.close();
                },
                error: function (xhr, status, p3, p4) {
                    var err = "Error " + " " + status + " " + p3;
                    if (xhr.responseText && xhr.responseText[0] == "{")
                        err = JSON.parse(xhr.responseText).message;
                    alert(err + '不合格状态修改失败！！！请点击重新修改');
                }
            });
    }

</script>
{% endblock body_middle %}